package com.xxcxcxcx.jobsystem.common.pack;

import com.xxcxcxcx.jobsystem.Main;
import com.xxcxcxcx.jobsystem.packet.ServerLevelPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;

import java.util.Optional;

public class Networking {
    public static SimpleChannel INSTANCE;
    public static final String VERSION = "1.0";
    private static int ID = 0;

    public static int nextID() {
        return ++ID;
    }

    public static void registerMessage() {
        INSTANCE = NetworkRegistry.newSimpleChannel(
                new ResourceLocation(Main.MOD_ID, "job_networking"),
                () -> VERSION,
                (version) -> version.equals(VERSION),
                (version) -> version.equals(VERSION)
        );
        /*INSTANCE.messageBuilder(ServerLevelPacket.class, nextID())
                .encoder(ServerLevelPacket::write)
                .decoder(ServerLevelPacket::new)
                .consumer(ServerLevelPacket::handler)
                .add();*/
        INSTANCE.registerMessage(nextID(), ServerLevelPacket.class, ServerLevelPacket::write, ServerLevelPacket::new, ServerLevelPacket.LevelPacketHandler::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
    }
}
